package com.itheima.blog.admin.controller;

import com.itheima.blog.admin.service.MenuService;
import com.itheima.blog.admin.vo.CategoryMenuVO;
import com.itheima.common.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/categoryMenu")
@Api(value = "菜单信息相关接口", tags = {"菜单信息相关接口"})
@Slf4j
public class MenuController {

    @Autowired
    MenuService menuService;

//    @ApiOperation(value = "获取菜单列表", notes = "获取菜单列表", response = String.class)
//    @RequestMapping(value = "/getList", method = RequestMethod.GET)
//    public R getList(@Validated @RequestBody CategoryMenuVO categoryMenuVO, BindingResult result) {
//
//        // 参数校验
//        return R.ok(menuService.getPageList(categoryMenuVO));
//    }

    @ApiOperation(value = "获取所有菜单列表", notes = "获取所有列表", response = String.class)
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    public R getAll(@RequestParam(value = "keyword", required = false) String keyword) {
        return R.ok(menuService.getAllList(keyword));
    }

    @ApiOperation(value = "获取所有二级菜单-按钮列表", notes = "获取所有二级菜单-按钮列表", response = String.class)
    @RequestMapping(value = "/getButtonAll", method = RequestMethod.GET)
    public R getButtonAll(@RequestParam(value = "keyword", required = false) String keyword) {

        return R.ok(menuService.getButtonAllList(keyword));
    }

    @ApiOperation(value = "增加菜单", notes = "增加菜单", response = String.class)
    @PostMapping("/add")
    public R add(@Validated @RequestBody CategoryMenuVO categoryMenuVO, BindingResult result) {
        menuService.addCategoryMenu(categoryMenuVO);
        return R.ok();
    }

    @ApiOperation(value = "编辑菜单", notes = "编辑菜单", response = String.class)
    @PostMapping("/edit")
    public R edit(@Validated @RequestBody CategoryMenuVO categoryMenuVO, BindingResult result) {
        menuService.editCategoryMenu(categoryMenuVO);
        return R.ok();
    }

    @ApiOperation(value = "删除菜单", notes = "删除菜单", response = String.class)
    @PostMapping("/delete")
    public R delete(@Validated @RequestBody CategoryMenuVO categoryMenuVO, BindingResult result) {
        menuService.deleteCategoryMenu(categoryMenuVO);
        return R.ok();
    }


}